@extends('layouts.back_stage')
@section('style')
    @parent
    <link rel="stylesheet" href="{{env('CDN_DOMAIN_NAME')}}/css/dateSelect.css"/>
@endsection
@section('script')
    @parent
    <script src="{{env('CDN_DOMAIN_NAME')}}/js/dateSelect.js"></script>
@endsection
@section('content')
    <style>
        .form-control{font-size:12px;}
    </style>
    <div class="container">
        <div style="padding:20px 20px 20px 0;overflow:hidden;"><h3 style="float:left;">出仓订单关联列表</h3></div>
        <div>
            <form action="/out-stage" role="form" style="display:inline-block;">
                @if($self_company_id == 1)
                    <label>选择公司：</label>
                    <select name="company_id" id="sort" class="address" style="width: 150px">
                        @if(isset($_GET['company_id']) && $_GET['company_id'])
                            <option value="{{$_GET['company_id']}}" selected>{{ $company_name[$_GET['company_id']]}}</option>
                        @endif
                        <option value="">全部公司</option>
                        @foreach($company_name as $k=>$v)
                            <option value="{{ $k }}">{{ $v }}</option>
                        @endforeach
                    </select>
                @else
                    <input type="hidden" name="company_id" value="{{ $self_company_id }}">
                @endif
                <label>手机号：</label><input type="text"  placeholder="请输入手机号" class="form-control tel_num" style="width: 150px;display: inline-block;" value="{{ $select['user_tel'] }}" name="user_tel">
                <label>运单号：</label><input type="text"  placeholder="请输入运单号" class="form-control waybill" style="width: 200px;display: inline-block;" value="{{ $select['user_num'] }}" name="user_num">
                <label>时间：</label><input id="date1" class="form-control start_time" style="width:120px;display: inline-block;background:#fff;" name="start_at" type="text" value="{{ $select['start_at'] }}" readonly placeholder="开始时间" />
                <input id="date2" class="form-control end_time"  name="end_at" style="width:120px;display: inline-block;background:#fff;" type="text" value="{{ $select['end_at'] }}" readonly placeholder="结束时间" />
                <button class="btn btn-info" style="margin-bottom:3px;">搜索</button>
            </form>
            <a class="btn btn-primary" style="float: right;margin-right:30px;" href="javascript:;" onclick="Export()">导出</a>
        </div>
        <span style="display:none;" class="info_sum">{{$orders_count}}</span>
        <table class="table table-hover" style="margin-top: 20px;">
            <thead>
            <tr>
                <th class="col-sm-2">订单号</th>
                <th class="col-sm-2">订单信息</th>
                <th class="col-sm-1">收件人</th>
                <th class="col-sm-1">收件人手机号</th>
                <th class="col-sm-2">收件人地址</th>
                <th class="col-sm-1">用户手机号</th>
                <th class="col-sm-1">数量/手</th>
                <th class="col-sm-1">预发货时间</th>
                <th class="col-sm-2">操作</th>
            </tr>
            @if($is_empty)
                <tr><td style="font-size: 18px;text-align: center" colspan="10">找不到该数据...</td></tr>
            @endif
            </thead>
            <tbody>
            @foreach($orders as $order)
                <tr>
                    <td>{{ $order->ordernum }}</td>
                    <td>
                        <div>
                            <img src="{{ env('CDN_DOMAIN_NAME') }}/upload/{{ $order->face }}" style="width:50px;float:left;margin-top:11px;">
                            <div style="display: inline-block;position: relative;top:0;left:10px">
                                <div>商品名称: {{ $order->title }}</div>
                                <div>款号: {{ $order->girard }}</div>
                                <div>颜色: {{ $order->color }}</div>
                                <div>数量:{{ $order->num }}手</div>
                            </div>
                        </div>
                    </td>
                    <td> {{ $order->addressee_name }}</td>
                    <td> {{ $order->addressee_tel }}</td>
                    <td> {{ $order->addressee_place }}</td>
                    <td> {{ $order->tel }}</td>
                    <td> {{ $order->num }}</td>
                    <?php
                    $nowtime = time();
                    if($nowtime <= strtotime($order->estimate_send_at) ){
                    ?>
                    <td>{{ $order->estimate_send_at }}</td>
                    <?php
                    }else{
                    ?>
                    <td style="color:red">{{ $order->estimate_send_at }}</td>
                    <?php } ?>
                    {{--<td>{{ $order->estimate_send_at }}</td>--}}
                    <td>
                        @if($order->status == 4)
                            @if($order->associated_at)
                                <button class="btn btn-success" disabled="true"><i class="fa fa-edit"></i>已关联</button>
                            @endif
                            {{--<button class="btn btn-success" disabled="true"><i class="fa fa-edit"></i>已关联</button>--}}
                            <button class="btn btn-info" onclick="sendGoods({{ $order->id }})">发货</button>
                        @elseif($order->status == 7)
                            @if($order->associated_at)
                                <button class="btn btn-success" disabled="true"><i class="fa fa-edit"></i>已关联</button>
                            @endif
                            <button class="btn btn-default" style="background-color: #eee" disabled="true"><i class="fa fa-edit"></i>已发货</button>
                            <button class="btn btn-default" onclick="sendGoods({{ $order->id }})">查看</button>
                        @elseif($order->status == 5)

                            @if($order->associated_at)
                                <button class="btn btn-success" disabled="true"><i class="fa fa-edit"></i>已关联</button>
                            @endif
                            <button class="btn btn-default" style="background-color: #eee" disabled="true"><i class="fa fa-edit"></i>已收货</button>
                            <button class="btn btn-default" onclick="sendGoods({{ $order->id }})">查看</button>
                        @elseif($order->status == 3||$order->status == 6)
                            <a class="btn btn-primary" href="/out-stage/associate?id={{$order->id}}"><i class="fa fa-edit"></i>关联二级二维码</a>
                            <button class="btn btn-info" onclick="sendGoods({{ $order->id }})">发货</button>
                        @endif
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        <div style="float: right"><div style="float: right;margin:20px 0;"><button class="btn btn-info" onclick="returnPage()" style="float:right;">跳转</button><input type="text" class="form-control returnPage" style="width:6rem;float: right;margin:0 5px;"></div>{{$orders->appends(['company_id'=>$company_id,'user_tel'=>$select['user_tel'],'user_num'=>$select['user_num'],'start_at'=>$select['start_at'],'end_at'=>$select['end_at']])->links()}}</div>
    </div>
    <script>
        @if(isset($_GET['page']))
            var page='{{ $_GET['page'] }}';
        @else
            var page = 1;
        @endif
        function sendGoods(id) {
            window.location.href = '/out-stage/expressDelivery?id='+id+'&page='+page;
        }
        /*日期插件初始化*/
        $("#date1").dateSelect();
        $("#date2").dateSelect();
        /*导出*/
        function Export(){
            var company_id=$("#sort").val();
            var start_at=$(".start_time").val();
            var end_at=$(".end_time").val();
            if($(".start_time").val()!='' && $(".end_time").val()!=''){
                var start=Date.parse(new Date(start_at));
                var end=Date.parse(new Date(end_at));
                if(parseInt(end)-parseInt(start)<0){
                    $(".faceImg").attr("src","/img/weep.png");
                    $(".oHandle").text("结束时间不能大于开始时间");
                    $(".oSuccess").show(0).delay(1000).hide(0);
                    return false;
                }
            }
            window.location.href="/excel/getOrderExcel?company_id="+company_id+"&start_at="+start_at+"&end_at="+end_at;
        }
    </script>
@endsection